﻿Imports Entities
Imports DataAccess
Public Class CalleBL
    Public Shared Function ListByVillaId(ByVal zId As Long) As List(Of CALLES)
        Dim lista As New List(Of CALLES)
        Try
            lista = CalleDAL.ListByVillaId(zId)
            If lista.Count > 0 Then
                Return lista
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Debug.Print(ex.Message)
            Return Nothing
        End Try
    End Function
    Public Shared Function List() As List(Of CALLES)
        Dim lista As New List(Of CALLES)
        lista = CalleDAL.List
        If lista.Count > 0 Then
            Return lista
        Else
            Return Nothing
        End If
    End Function
    Public Shared Function Save(ByVal zObject As CALLES) As Boolean
        If CalleDAL.Exist(zObject.CALLE) Then
            CalleDAL.Update(zObject)
            Return True
        Else
            Return CalleDAL.Create(zObject)
        End If
    End Function

    Public Shared Function Delete(ByVal zId As Long) As Boolean
        Return CalleDAL.Delete(zId)
    End Function

    Public Shared Function GetNombre(ByVal zId As Long) As String
        Dim obj As New CALLES
        obj = CalleDAL.SearchById(zId)
        If Not IsNothing(obj) Then
            Return obj.NOMBRE
        Else
            Return ""
        End If
    End Function
    Public Shared Function SearchById(ByVal zId As Long) As CALLES
        Return CalleDAL.SearchById(zId)
    End Function
    Public Shared Function ListP() As List(Of CallesP)
        Dim lista As New List(Of CALLES)
        Dim listaF As New List(Of CallesP)
        lista = CalleBL.List
        If IsNothing(lista) Then Return Nothing
        For Each rec In lista
            Dim p As New CallesP
            With p
                .CalleId = rec.CALLE
                .Nombre = rec.NOMBRE
                .VIlla = VillaBL.GetNombre(rec.VILLA)
            End With
            listaF.Add(p)
        Next
        Return listaF
    End Function
End Class
